package sol.leetcode;

/**
 * Single Number II
 */
public class Issue137 {
    public int singleNumber(int[] nums) {
        int len = nums.length, result = 0;
        //逐位处理
        for (int i = 0; i < 32; ++i) {
            int bitSum = 0;   //记录每一位的和
            for (int j = 0; j < len; ++j) {
                bitSum += (nums[j] >> i) & 1;
            }
            result |= (bitSum % 3) << i;
        }
        return result;
    }

    public static void main(String[] args) {
        int[] nums = {1, 1, 1,3};
        System.out.println(new Issue137().singleNumber(nums));
    }
}
